
#include "AllInc.h"

#include "Graphic.h"
#include "Draw2D.h"


Graphic::Graphic():dots(MAX_GRAPHICS_NUM)
{
	NeedRedraw();
}
void Graphic::Clear()
{
	dots.Clear();
	NeedRedraw();
}
void Graphic::AddGraphic(vec2*p,int num,vec4 ncolor)
{
	color[dots.GetNum()] = ncolor;
	dots.AddSet(p,num);
	NeedRedraw();
}

void Graphic::PureDraw()
{
	if(!dots.GetNum()){return;}
	if(!dots.GetNum(0)){return;}
	dots.Start();
	minBB = *dots.GetCurrent();
	maxBB = minBB;
	while(!dots.DoneI())
	{
		glColor4fv(&(color+dots.I())->x);
		vec2 *cur_dot;
		glBegin(GL_LINE_STRIP);
		while(!dots.DoneJ())
		{
			cur_dot = dots.GetCurrent();
			glVertex2fv(&cur_dot->x);
			maxBB = vec2::Max(maxBB,*cur_dot);
			minBB = vec2::Min(minBB,*cur_dot);

			dots.NextJ();
		}
		glEnd();
		

		dots.NextI();
	}
//	glColor4f(0,0,1,0.3f);
//	DrawRectangle(minBB,maxBB);
//	DrawGrid(minBB-vec2(0.4f),maxBB+vec2(0.4f),0.1f);


}
